var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../http/carApi")), e = require("../../utils/tool"), i = new t.default();

Component({
    properties: {
        status: {
            type: Number,
            value: 0
        },
        car: {
            type: Object,
            observer: function(t) {
                var e = t.ipEnglishName || ("潮玩公社" == t.ipName ? "" : t.ipName);
                this.setData({
                    goodsTitle: e + t.productTitle
                });
            }
        }
    },
    observers: {
        "car.quantity": function(t) {
            this.setData({
                quantity: t
            });
        },
        "car.invalidStatus": function(t) {
            this.setData({
                invalidStatus: this.data.invalidStatusList[t]
            });
        }
    },
    data: {
        quantity: 1,
        goodsTitle: "",
        invalidStatusList: [ "正常", "未开售", "无资格", "超限购", "已售罄", "库存不足", "已下架" ],
        invalidStatus: ""
    },
    methods: {
        onChange: function(t) {
            console.log(t);
        },
        plus: function() {
            this.data.quantity + 1 > this.properties.car.stock ? (0, e.toastToPage)("数量超出库存上限~") : this.properties.car.limitNum && this.properties.car.limitNum && this.data.quantity + 1 > this.properties.car.limitNum ? (0, 
            e.toastToPage)("数量超出每人限购上限~") : this.changeCount(0);
        },
        minus: function() {
            1 != this.data.quantity ? this.changeCount(1) : (0, e.toastToPage)("数量低于范围~");
        },
        showDeleteDialog: function() {
            this.selectComponent("#clear-dialog").showPopup();
        },
        delete: function() {
            var t = this;
            i.deleteCarGoods(this.properties.car.productId).then(function(i) {
                (0, e.toastToPage)(), t.triggerEvent("refresh", {});
            }).catch(function(t) {
                (0, e.toastToPage)(t.msg);
            });
        },
        changeCount: function(t) {
            var e = this;
            wx.showLoading({
                title: "加载中",
                mask: !0
            }), i.changeCarCount({
                productId: this.properties.car.productId,
                quantity: 1,
                changeType: t
            }).then(function(i) {
                t ? e.setData({
                    quantity: e.data.quantity - 1
                }) : e.setData({
                    quantity: e.data.quantity + 1
                }), wx.hideLoading(), e.triggerEvent("changeCarProCount", {
                    product: e.properties.car,
                    quantity: e.data.quantity
                });
            }).catch(function(t) {
                wx.hideLoading();
            });
        },
        tappingSelect: function(t) {
            this.triggerEvent("sendId", {
                productId: this.properties.car.productId,
                select: t.detail.select
            });
        },
        toDirectBuyDetails: function() {
            wx.navigateTo({
                url: "/pages/direct-buy-details/direct-buy-details?productId=".concat(this.properties.car.productId)
            });
        }
    }
});